package com.hanbang.maige.pressenter.aboutme;

import android.support.design.widget.Snackbar;

import com.hanbang.maige.code.base.presenter.BasePresenter;
import com.hanbang.maige.mode.HttpRequest;
import com.hanbang.maige.mode.httpresponse.BaseHttpResponse;
import com.hanbang.maige.mode.javabean.aboutme.MyInfoData;
import com.hanbang.maige.mode.javabean.huodong.HuoDongPublishData;
import com.hanbang.maige.utils.http.httpquest.HttpCallBack;
import com.hanbang.maige.utils.http.httpquest.HttpRequestParam;
import com.hanbang.maige.utils.other.StringUtils;
import com.hanbang.maige.utils.ui.SnackbarUtil;
import com.hanbang.maige.view.aboutme.IAboutMeBaseView;

import static com.hanbang.maige.mode.javabean.base.UserData.userData;

/**
 * Created by 方朝辉 on 2016/10/26.
 */

public class GeRenZiLiaoPresenter extends BasePresenter<IAboutMeBaseView.IGeRenZiLiaoView> {
    public void updateUser(final MyInfoData myInfoData) {
        if (myInfoData == null) return;
        HttpCallBack.Buider buider = new HttpCallBack.Buider(this);
        buider.setHint("保存中");
        HttpCallBack<BaseHttpResponse> callBack = new HttpCallBack<BaseHttpResponse>(buider) {
            @Override
            public void onSuccess(BaseHttpResponse result) {
                super.onSuccess(result);
                if (result.isSucceed()) {
                    mvpView.showSnackbar(result.getMsg(), SnackbarUtil.Info, true, new Snackbar.Callback() {
                        @Override
                        public void onDismissed(Snackbar snackbar, int event) {
                            super.onDismissed(snackbar, event);
                            userData.setHeadPhotoSma(myInfoData.touxiangPath);
                            userData.setHeadPhotoMid(myInfoData.touxiangPath);
                            userData.setNiChenName(myInfoData.getNiChenName());
                            userData.setEmail(myInfoData.getEmail());
                            userData.setBiaoQian(myInfoData.getBiaoQianId());
                            userData.setHyValueName(myInfoData.getBiaoqianData().getHyValueName());
                            userData.setDbUserData();
                            mvpView.complete();
                        }
                    });
                } else {
                    mvpView.showErrorSnackbar(result.getMsg());
                }
            }
        };

        HttpRequestParam param = new HttpRequestParam("UpdateUser");
        param.addParam("avatar", myInfoData.touxiangPath);
        param.addParam("NiChenName", myInfoData.getNiChenName());
        param.addParam("Email", myInfoData.getEmail());
        param.addParam("BiaoQian", myInfoData.getBiaoQianId());
        mvpView.addSubscription(HttpRequest.uploadFiles(callBack, param));

    }
}
